<template>
  <div class="user-containier">
    <div class="user">
      <div class="userpic">
        <img v-imgError="defautImg" :src=" user.avatarName ? baseApi + '/avatar/' + user.avatarName : defautImg" alt="">
      </div>
      <span class="name">{{ user.username }}</span>
      <div
        v-for="(item, index) in items"
        :key="index"
        class="item"
        :class="[$store.getters.activeItem === index ? 'current' : '']"
        @click="changeItem(index)"
      >
        {{ item }}
      </div>
    </div>
    <div class="info">
      <!-- <router-view/> -->
      <UserInfo v-if="$store.getters.activeItem ===0" />
      <UserReceive v-else-if="$store.getters.activeItem ===1" />
      <UserReceiveRecord v-else-if="$store.getters.activeItem ===2" />
      <UserReturnRecord v-else-if="$store.getters.activeItem ===3" />
      <UserAppointment v-else />
    </div>
  </div>
</template>

<script>
import { getStoreHouseAPI } from '@/api/hazardousChemicals.js'
import defautImg from '@/assets/images/avatar.png'
import { mapGetters } from 'vuex'
import UserInfo from './info/index.vue'
import UserReceive from './receive/index.vue'
import UserReceiveRecord from './receiveRecord/index.vue'
import UserAppointment from './appointment'
import UserReturnRecord from './returnRecord'
export default {
  components: {
    UserInfo,
    UserReceive,
    UserReceiveRecord,
    UserAppointment,
    UserReturnRecord
  },
  data() {
    return {
      defautImg,
      items: ['消息中心', '物料领用', '领用记录','归还记录', '我的预约'],
    }
  },
  created() {
    this.$store.dispatch('hjuser/getStoreHouse')
  },
  computed: {
    ...mapGetters(['user', 'baseApi']),
  },
  methods: {
       async getStoreHouse() {
      const res1 = await getStoreHouseAPI(1)
      const res2 = await getStoreHouseAPI(2)
      const res3 = await getStoreHouseAPI(3)
      this.reagentData = res1.data
      this.chemicalData = res3.data
      this.standardSubstanceData = res2.data
    },
    changeItem(index) {
      if(index===1){
        this.$store.dispatch('hjuser/getStoreHouse')
      }
      this.$store.commit('hjuser/updatedActiveItem', index)
    }
  }
}
</script>

<style scoped lang="scss">
.user-containier {
  display: flex;
  justify-content: space-between;
  > div {
    background-color: #f9f9fa;
    border-radius: 10px;
    min-height: 800px;
    // max-height: 800px;
    // overflow: auto;
  }
  .current {
    background-color: #edeffc;
    color: #5f6af2;
    background-color: #578bf0;
    color: #fff;
  }
  .user {
    padding: 30px;
    width: 18%;
    display: flex;
    flex-direction: column;
    align-items: center;
    // max-height: 800px;
    .userpic {
      width: 80px;
      height: 80px;
      border-radius: 50%;
      margin-bottom: 15px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }
    .name {
      width: 120px;
      overflow: hidden;
      text-overflow: ellipsis;
      text-align:center;
      white-space: nowrap;
      font-size: 20px;
      margin-bottom: 30px;
    }
    .item {
      width: 100%;
      height: 45px;
      line-height: 45px;
      text-align: center;
      margin-bottom: 15px;
      border-radius: 6px;
      font-size: 20px;

      &:hover {
        // background-color: #edeffc;
        // color: #5f6af2;
      }
    }
  }
  .info {
    width: 80%;
    padding: 15px;
  }
}
</style>
